package org.itboys.core.controller.web;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.core.entity.mysql.SundayScore;
import org.itboys.core.service.mongo.web.SundayMemberService;
import org.itboys.core.service.mysql.front.SundayFrontScoreService;
import org.itboys.core.service.mysql.web.SundayScoreService;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Auther: 罗尧坤
 * Date: 2018/8/21
 * Description:
 */
@Controller
@RequestMapping("/sunday/web/score")
public class SundayScoreController extends BaseController {
    @Autowired
    private SundayScoreService scoreService;

    /**
     * @param request
     * @param model
     * @return
     */
    @RequestMapping("/index")
    public String index(HttpServletRequest request,
                        @RequestParam(value = "memberId", required = true) Long memberId,
                        Model model) {
        model.addAttribute("memberId", memberId);
        return "/sunday/score/index";
    }

    @RequestMapping("/select")
    public void select(HttpServletRequest request,
                       HttpServletResponse response,
                       @RequestParam(value = "memberId", required = true) Long memberId
    ) {
        try {
            PageResult<SundayScore> result = scoreService.selectScore(request, memberId);
            JsonPageUtils.renderJsonPage(result.getTotal(), result.getData(), response);
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }

    }


}
